#ifndef _QTWAIN_H_
#define _QTWAIN_H_

#include "twaincpp.h"
#include <QDebug>
#include <QComboBox>
#include <QObject>
#include <QPixmap>
#include <QImage>
#include <limits.h>
#include <QWidget>
#include "dib.h"
#include "dibutil.h"
#include "dibapi.h"
#pragma execution_character_set("utf-8")；

class CDIB;

const unsigned int AnyCount = UINT_MAX;

class QTwain : public QObject,public CTwain
{	
    Q_OBJECT
    Q_GUI_EXPORT HBITMAP qt_pixmapToWinHBITMAP(const QPixmap &p, int hbitmapFormat = 0);

public:

    QTwain(QWidget* parent = nullptr, HWND id = nullptr);

	virtual ~QTwain();

    void setParent(QWidget* parent);
    bool selectSource();
    bool acquire(unsigned int maxNumImages = AnyCount);

    bool isValidDriver() const;

    void setEmitPixmaps(bool emitThem = true)
    {
        m_bEmitPixmaps = emitThem;
    }
    static QPixmap* convertToPixmap();
    static QPixmap* convertToPixmap(CDIB* pDib);

    static QImage* convertToImage(CDIB* pDib,unsigned int nWidth = 0,unsigned int nHeight = 0);
    static CDIB* convertToDib(QPixmap* pPixmap,unsigned int nWidth = 0,unsigned int nHeight = 0);

    inline bool emitPixmaps() const
    {
        return m_bEmitPixmaps;
    }

signals:
    void already_get_sour_list();
    void pixmapAcquired(QPixmap* pPixmap);

public:
	virtual bool onSetParent();
	virtual void CopyImage(HANDLE hBitmap, TW_IMAGEINFO& info);
	void Create24Bit(CDIB& source,CDIB& dest);
    void SetImage(HANDLE hBitmap,int bits);


    int type;
    int papersize;
    int img_model;
    int fenbianlv;
    QWidget* m_pParent;
    bool m_bEmitPixmaps;//是否发射QPixmap格式的图片，否则发射CDIB格式的位图


};

#endif // !_QTWAIN_H_
